// Starfield.cpp //
#include "Starfield.h"

//creates the background randomly

Starfield::Starfield()
{
	lastSpawn = 0.0f;
}

void Starfield::Update(float deltaTime)
{
	lastSpawn += deltaTime;
	if(lastSpawn > StarfieldSpawnTime)
	{
		for(int i = 0; i < 3; ++i)
		{
			int newRand = rand() % 1000;
        	char starkey[9];
			//if adds non star backround objects
			if(newRand == 1 || newRand == 0)
				if(i==0)
				{
					sprintf(starkey, "Gal%d", newRand + 1);
				}
				else if(i==1)
				{
					sprintf(starkey, "PlanetB%d", newRand + 1);
				}
				else if(i==2)
				{
					sprintf(starkey, "Planet%d", newRand + 1);
				}
				else
				sprintf(starkey, "Star%d", i + 1);
			else
				sprintf(starkey, "Star%d", i + 1);
			Star* star = new Star(starkey);
			star->position = Vector(rand() % ScreenWidth, -star->sprite->origin.Y);
			star->speed = 100.0f + i * 35.0f;
		}
		
		lastSpawn = 0.0f;
	}
}
